export class Route {

    static to(page, data, options) {

        const base_url = `/pages/${page}/${page}`;
        const url =  base_url + this.contact_url_params(data);

        wx.navigateTo(Object.assign({ url }, options));
    }

    static redirectTo(page, data, options) {

        const base_url = `/pages/${page}/${page}`;
        const url =  base_url + this.contact_url_params(data);

        wx.redirectTo(Object.assign({ url }, options));
    }

    static back() {
        wx.navigateBack();
    }

    static contact_url_params(params) {

        let result = ''

        for (let param in params) {
            result += `&${param}=${params[param]}`
        }

        if (result) result = result.replace('&', '?')

        return result
    }
}